package cn.controller;

import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 抽取controller 企业id
 *
 * @author Mxb
 * @version 1.0
 * @date 2020/7/1 16:48
 */
public class BaseController {


    public HttpServletRequest request;
    public HttpServletResponse response;

    protected String companyId;

    protected String companyName;

    protected Claims claims;

    @ModelAttribute
    public void setResAndReq(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;

        Object obj = request.getAttribute("user_claims");

        if (obj != null) {
            // 强制转型
            this.claims = (Claims) obj;
            this.companyId= (String) claims.get("companyId");
            this.companyName = (String) claims.get("companyName");
        }
        /**
         * 目前使用
         */
        //以后解决companyId
        this.companyId = "1";
        this.companyName = "哈哈";
    }
}
